package com.sec.etech.org.model;

import org.openbpm.base.api.model.Tree;
import org.openbpm.org.core.model.Group;
import org.openbpm.org.core.model.OrgTree;

import java.util.*;
import java.util.stream.Collectors;

public class EtechOrgTree extends Group implements Tree<EtechOrgTree> {
    public static final String ICON_COMORG = "/styles/theme/default/images/icons/u_darkblue/u_zzgl_darkblue.png";
    protected Integer sn;
    protected String icon;
    protected boolean nocheck = false;
    protected boolean chkDisabled = false;
    protected boolean checked = false;
    protected boolean click = true;
    protected String title = "";
    protected List<EtechOrgTree> children;

    public EtechOrgTree() {
    }

    public EtechOrgTree(String name, String id, String parentId, String icon) {
        this.setName(name);
        this.parentId = parentId;
        this.id = id;
        this.icon = icon;
    }

    public static List<EtechOrgTree> GroupList2TreeList(List<Group> groupList, String icon) {
        if (groupList != null && groupList.size() != 0) {
            List<EtechOrgTree> groupTreeList = new ArrayList();
            Iterator var3 = groupList.iterator();

            while(var3.hasNext()) {
                Group group = (Group)var3.next();
                EtechOrgTree grouptree = new EtechOrgTree(group);
                grouptree.setIcon(icon);
                groupTreeList.add(grouptree);
            }

            return groupTreeList;
        } else {
            return Collections.emptyList();
        }
    }

    public static List<EtechOrgTree> list2tree(List<EtechOrgTree> list) {
        List<EtechOrgTree> result = new ArrayList();
        Map<Object, EtechOrgTree> hash = (Map)list.stream().collect(Collectors.toMap((ux) -> {
            return ux.getId();
        }, (ux) -> {
            return ux;
        }));
        Iterator var3 = list.iterator();

        while(var3.hasNext()) {
            EtechOrgTree u = (EtechOrgTree)var3.next();
            EtechOrgTree p = (EtechOrgTree)hash.get(u.getParentId());
            if (p == null) {
                result.add(u);
            } else {
                if (p.getChildren() == null) {
                    p.setChildren(new ArrayList());
                }

                p.getChildren().add(u);
            }
        }

        return result;
    }

    public EtechOrgTree(Group group) {
        this.id = group.getId();
        this.name = group.getName();
        this.code = group.getCode();
        this.sn = group.getSn();
        this.parentId = group.getParentId();
        this.type = group.getType();
        if (!this.name.contains("style=")) {
            this.title = this.name;
        }

    }

    public void setName(String name) {
        this.name = name;
        if ("".equals(this.title) && !this.name.contains("style=")) {
            this.title = name;
        }

    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Integer getSn() {
        return this.sn;
    }

    public void setSn(Integer sn) {
        this.sn = sn;
    }

    public String getIcon() {
        return this.icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public boolean isNocheck() {
        return this.nocheck;
    }

    public void setNocheck(boolean nocheck) {
        this.nocheck = nocheck;
    }

    public boolean isChkDisabled() {
        return this.chkDisabled;
    }

    public boolean isClick() {
        return this.click;
    }

    public void setClick(boolean click) {
        this.click = click;
    }

    public void setChkDisabled(boolean chkDisabled) {
        this.chkDisabled = chkDisabled;
    }

    public List<EtechOrgTree> getChildren() {
        return this.children;
    }

    public void setChildren(List<EtechOrgTree> list) {
        this.children = list;
    }

    public boolean isChecked() {
        return this.checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
}
